<!DOCTYPE html>
<html>
<!--
Copyright 2007 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MP Unit Tests - mp.tools.Scheme</title>
<script src="/js/vendor/closure-library/closure/goog/base.js"></script>
<script>
    goog.require('goog.debug.Logger');
    goog.require('goog.math.Matrix');
    goog.require('goog.object');
    goog.require('goog.testing.jsunit');
</script>
<script src="/js/mp/tools/matrix.js"></script>
<script src="/js/mp/tools/scheme.js"></script>
</head>
<body>
<pre>
<script>
    function testReflectNonEmpty() {
        var a1 = [  [2, 0, 2, 0, 2, 0],
                    [0, 2, 3, 4, 5, 0],
                    [0, 3, 4, 5, 6, 0],
                    [2, 4, 5, 6, 7, 0],
                    [2, 0, 0, 0, 0, 0]];
                    
        var a2 = [  [2, 0, 2, 0, 2, 2],
                    [0, 2, 3, 4, 5, 0],
                    [0, 3, 4, 5, 6, 0],
                    [2, 4, 5, 6, 7, 2],
                    [2, 0, 2, 0, 2, 2]];

        var m1 = new mp.tools.Scheme(a1);
        m1.reflectNonEmpty(2);
        var m2 = new mp.tools.Scheme(a2);
        
        assertTrue(m2.equals(m1));
    }

    function testGetNonEmptyEdgeIdxs() {
        var a1 = [  [2, 0, 2, 0, 2, 0],
                    [0, 2, 3, 4, 5, 0],
                    [0, 3, 4, 5, 6, 0],
                    [2, 4, 5, 6, 7, 0],
                    [2, 0, 0, 0, 0, 0]];
                    
        var a2 = [  [0,2,4],
                    [0,3,4] ];

        var m1 = new mp.tools.Scheme(a1);
        var a3 = m1.getNonEmptyEdgeIdxs(2, false);
        var a4 = m1.getNonEmptyEdgeIdxs(2, true);

        assertArrayEquals('1. Line array should be the same', a2[0], a3);
        assertArrayEquals('2. Line array should be the same', a2[1], a4);
    }

    function testGetValueIdxsMap() {
        var a1 = [  [2, 0, 2, 0, 2, 0],
                    [0, 2, 3, 4, 5, 0],
                    [0, 3, 4, 5, 6, 0],
                    [2, 4, 5, 6, 7, 0],
                    [2, 0, 0, 0, 0, 0]];
                    
        var map1 = new goog.structs.Map();
        map1.set(4, [
            new goog.math.Coordinate(3, 1),
            new goog.math.Coordinate(2, 2),
            new goog.math.Coordinate(1, 3)]);

        var m1 = new mp.tools.Scheme(a1);
        var map2 = m1.getValueIdxsMap();

        assertEquals(map2.getCount(), 7);

        assertArrayEquals('Array should be the same', map1.get(4), map2.get(4));
    }

    function testGetNeighbours() {
        var a1 = [  [2, 0, 2, 0, 2, 0],
                    [0, 2, 3, 4, 5, 0],
                    [0, 3, 4, 5, 6, 0],
                    [2, 4, 5, 6, 7, 0],
                    [2, 0, 0, 0, 0, 0]];
                    
        var m1 = new mp.tools.Scheme(a1);
        var vals1 = m1.getNeighbours(0, 5);
        var vals2 = m1.getNeighbours(1, 1, true);
        var vals3 = m1.getNeighbours(4, 2);

        assertEquals(vals1.length, 2);
        assertEquals(vals2.length, 8);
        assertEquals(vals3.length, 3);
        
        goog.array.sort(vals1);
        goog.array.sort(vals2);
        goog.array.sort(vals3);

        assertArrayEquals('Array should be the same', vals1, [0,2]);
        assertArrayEquals('Array should be the same', vals2, [0,0,0,2,2,3,3,4]);
        assertArrayEquals('Array should be the same', vals3, [0,0,5]);
    }
</script>
</pre>
</body>
</html>
